//
//  SWLoginViewController.swift
//  BaseDemo
//
//  Created by linhan on 16/2/18.
//  Copyright © 2016年 me. All rights reserved.
//

import Foundation
import UIKit
class SWLoginViewController: SWBaseViewController,SWAPIComponent,UITextFieldDelegate,WeiboHelperDelegate,WeixinHelperDelegate,QQSDKHelperDelegate,ScrollADImageDelagate
{
    
    var autoLogin:Bool = false
    
    private let AuthViewHeight:CGFloat = 130.0
    private let LoginBottomViewHeight:CGFloat = 126.0
    private let LoginTopViewNormalHeight:CGFloat = 270
    
    lazy private var _loginView:UIView = UIView()
    lazy private var _loginTopView:UIView = UIView()
    lazy private var _loginBottomView:UIView = UIView()
    
    lazy private var _telTextField:ImageTextField = ImageTextField()
    lazy private var _passwordTextField:ImageTextField = ImageTextField()
    
    lazy private var _loginBtn:UIButton = UIButton(type:.system)
    lazy private var _bottomView:UIView = UIView()
    lazy private var _pageControl:UIPageControl = UIPageControl()
    private var _scrollADImage:ScrollADImage?
    
    override func viewDidLoad()
    {
        super.viewDidLoad()
        setup()
    }
    
    override func viewDidAppear(_ animated: Bool)
    {
        super.viewDidAppear(animated)
        if autoLogin && phone != "" && password != ""
        {
            loginBtnTapped()
        }
        
        WeixinHelper.shared().authViewController = self
        WeixinHelper.shared().delegate = self
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        view.endEditing(true)
    }
    
    deinit
    {
        trace("DEINIT AuthEntranceViewController")
        NotificationCenter.default.removeObserver(self)
    }
    
    override var prefersStatusBarHidden: Bool
    {
        return true
    }
    
    override var prefersNavigationBarHidden: Bool
    {
        return true
    }
    
    
    //MARK ============================================================================================
    //==============================           Getter And Setter        ===============================
    //=================================================================================================
    
    var password:String {
        get {
            return _passwordTextField.text ?? ""
        }
        set {
            _passwordTextField.text = newValue
        }
    }
    
    var phone:String {
        get {
            return _telTextField.text ?? ""
        }
        set {
            _telTextField.text = newValue
        }
    }
    
    //MARK ============================================================================================
    //==============================            Public Method           ===============================
    //=================================================================================================
    
    
    
    //MARK ============================================================================================
    //==============================            Private Method          ===============================
    //=================================================================================================
    
    
    private func setup()
    {
        view.backgroundColor = UIColor.white
        
        WeiboHelper.shared().delegate = self
        QQSDKHelper.shared().delegate = self
        
        introductionViewSetup()
        createBottomView()
        createFlowLoginView()
        
        //点击空白收起
        let tapGesture:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(viewTapped))
        let topViewTapGesture:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(viewTapped))
        view.addGestureRecognizer(tapGesture)
        _loginView.addGestureRecognizer(topViewTapGesture)
        
        
        
        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
    }
    
    private func introductionViewSetup()
    {
        let introductionView:UIView = UIView()
        introductionView.frame = view.bounds
        view.addSubview(introductionView)
        
        let scrollADImage = ScrollADImage(frame: introductionView.bounds)
        scrollADImage.delegate = self
        scrollADImage.autoScrollInterval = 6
        scrollADImage.backgroundColor = UIColor.white
        introductionView.addSubview(scrollADImage)
        _scrollADImage = scrollADImage
        
        _pageControl.backgroundColor = UIColor.clear
        _pageControl.currentPageIndicatorTintColor = UIColor(hex: 0xf8e9eb)
        _pageControl.isUserInteractionEnabled = false
        _pageControl.currentPage = 0
        
        introductionView.addSubview(_pageControl)
        
        DispatchQueue.global(priority: .default).async {
            var images:[UIImage] = []
            let sources:[String] = ["auth_img_introduction1.jpg", "auth_img_introduction2.jpg"]
            for source in sources
            {
                if let url = Bundle.main.url(forResource: source, withExtension: nil),
                   let data = try? Data(contentsOf: url),
                   let image = UIImage(data: data, scale: UIScreen.main.scale)
                {
                    images.append(image)
                }
            }
            DispatchQueue.main.async{
                scrollADImage.images = images
                self._pageControl.numberOfPages = images.count
                self._pageControl.sizeToFit()
                self._pageControl.center = CGPointMake(introductionView.width * 0.5, introductionView.height - 160)
            }
            
        }
    }
    
    private func createBottomView()
    {
        //登陆按钮
        let buttonTopMargin:CGFloat = 15
        let buttonLeftMargin:CGFloat = 42
        let buttonRightMargin:CGFloat = 42
        let buttonGrid:CGFloat = 30
        
        let bottomView:UIView = UIView()
        //bottomView.backgroundColor = UIColor.white
        bottomView.frame = CGRectMake(0, view.height - AuthViewHeight, view.width, AuthViewHeight)
        view.addSubview(bottomView)
        
        let wechatBtnWidth:CGFloat = (view.width - buttonGrid - buttonLeftMargin - buttonRightMargin) / 2
        let wechatBtn:UIButton = UIButton(type: .system)
        wechatBtn.setTitle("微信", for: .normal)
        wechatBtn.setTitleColor(UIColor(hex:0x595959), for: .normal)
        wechatBtn.titleLabel?.font = UIFont.systemFont(ofSize: 18)
        wechatBtn.layer.cornerRadius = 5
        wechatBtn.layer.masksToBounds = true
        wechatBtn.layer.borderWidth = 1
        wechatBtn.layer.borderColor = UIColor(hex: 0xe5e4e4).cgColor
        wechatBtn.backgroundColor = UIColor(hex: 0xffffff)
        wechatBtn.addTarget(self, action: #selector(wechatBtnTapped), for: .touchUpInside)
        wechatBtn.frame = CGRectMake(buttonLeftMargin, buttonTopMargin, wechatBtnWidth, 50)
        bottomView.addSubview(wechatBtn)
        
        let loginBtn:UIButton = UIButton(type: .system)
        loginBtn.setTitle("登录", for: .normal)
        loginBtn.setTitleColor(UIColor(hex:0x595959), for: .normal)
        loginBtn.titleLabel?.font = UIFont.systemFont(ofSize: 18)
        loginBtn.layer.cornerRadius = 5
        loginBtn.layer.masksToBounds = true
        loginBtn.layer.borderWidth = 1
        loginBtn.layer.borderColor = UIColor(hex: 0xe5e4e4).cgColor
        loginBtn.backgroundColor = UIColor(hex: 0xf8e9eb)
        loginBtn.addTarget(self, action: #selector(showLoginViewBtnTapped), for: .touchUpInside)
        loginBtn.frame = CGRectMake(wechatBtn.right + buttonGrid, buttonTopMargin, wechatBtnWidth, 50)
        bottomView.addSubview(loginBtn)
        
        let regBtn:UIButton = UIButton(type: .system)
        regBtn.setTitle("注册 >>", for: .normal)
        regBtn.setTitleColor(UIColor(hex:0xa4a4a4), for: .normal)
        regBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        regBtn.sizeToFit()
        regBtn.center = CGPointMake(bottomView.width * 0.5, wechatBtn.bottom + 34)
        regBtn.addTarget(self, action: #selector(regBtnTapped), for: .touchUpInside)
        bottomView.addSubview(regBtn)
    }
    
    private func createFlowLoginView()
    {
        let TextFieldWidth:CGFloat = view.width * 0.733
        let TextFieldHeight:CGFloat = 50
        let TextFieldLeftMargin:CGFloat = (view.width - TextFieldWidth) * 0.5
        let PlaceholderColor:UIColor = UIColor(hex: "0xababab")
        let InputColor:UIColor = UIColor.darkGray
        
        
        //输入时整个topview上移
        let loginViewHeight = LoginTopViewNormalHeight + LoginBottomViewHeight
        _loginView.frame = CGRectMake(0, view.height, view.width, loginViewHeight)
        _loginView.backgroundColor = UIColor.white
        view.addSubview(_loginView)
        
        _loginTopView.frame = CGRectMake(0, 0, view.width, LoginTopViewNormalHeight)
        _loginView.addSubview(_loginTopView)
        
        
        //手机输入框
        _telTextField.frame = CGRectMake(TextFieldLeftMargin, 37, TextFieldWidth, TextFieldHeight)
        _telTextField.textInset = UIEdgeInsetsMake(0, 18, 0, 18)
        _telTextField.font = UIFont.systemFont(ofSize:14)
        //_telTextField.textAlignment = .center
        _telTextField.keyboardType = .phonePad
        _telTextField.clearButtonMode = .whileEditing
        _telTextField.delegate = self
        _telTextField.attributedPlaceholder = NSMutableAttributedString(string: "请输入手机号码", attributes: [NSForegroundColorAttributeName:PlaceholderColor])
        _telTextField.textColor = InputColor
        _telTextField.layer.borderColor = UIColor(hex: 0xd0d0d0).cgColor
        _telTextField.layer.borderWidth = 1
        _telTextField.layer.cornerRadius = 4
        _telTextField.layer.masksToBounds = true
        _loginTopView.addSubview(_telTextField)
        
        _passwordTextField.frame = CGRectMake(TextFieldLeftMargin, _telTextField.bottom + 25, TextFieldWidth, TextFieldHeight)
        _passwordTextField.textInset = UIEdgeInsetsMake(0, 18, 0, 18)
        _passwordTextField.font = UIFont.systemFont(ofSize:14)
        _passwordTextField.attributedPlaceholder = NSMutableAttributedString(string: "请输入密码", attributes: [NSForegroundColorAttributeName:PlaceholderColor])
        _passwordTextField.textColor = InputColor
        //_passwordTextField.textAlignment = .center
        _passwordTextField.clearButtonMode = .whileEditing
        _passwordTextField.isSecureTextEntry = true
        _passwordTextField.returnKeyType = .go
        _passwordTextField.delegate = self
        _passwordTextField.layer.borderColor = UIColor(hex: 0xd0d0d0).cgColor
        _passwordTextField.layer.borderWidth = 1
        _passwordTextField.layer.cornerRadius = 4
        _passwordTextField.layer.masksToBounds = true
        _loginTopView.addSubview(_passwordTextField)
        
        
        //忘记密码
        let resetBtn:UIButton = UIButton(type:.system)
        resetBtn.titleLabel?.font = UIFont.systemFont(ofSize:14)
        resetBtn.setTitleColor(UIColor(hex:0x303332), for: .normal)
        resetBtn.setTitle("忘记密码?", for: .normal)
        resetBtn.sizeToFit()
        resetBtn.frame = CGRectMake(TextFieldLeftMargin, _passwordTextField.bottom + 20, resetBtn.width, resetBtn.height)
        resetBtn.addTarget(self, action: #selector(resetBtnTapped), for: .touchUpInside)
        _loginTopView.addSubview(resetBtn)
        
        
        
        //登录按钮
        _loginBtn.setTitleColor(UIColor.white, for: .normal)
        _loginBtn.titleLabel?.font = UIFont.systemFont(ofSize:18)
        _loginBtn.setTitle("登录", for: .normal)
        _loginBtn.layer.cornerRadius = 4
        _loginBtn.layer.masksToBounds = true
        _loginBtn.backgroundColor = UIColor(hex: 0xf46363)
        _loginBtn.frame = CGRectMake(TextFieldLeftMargin, _passwordTextField.bottom + 57, TextFieldWidth, 50)
        _loginBtn.addTarget(self, action: #selector(loginBtnTapped), for: .touchUpInside)
        _loginTopView.addSubview(_loginBtn)
        
        
        
        //===========第三方登陆===================
        
        _loginBottomView.frame = CGRectMake(0, loginViewHeight - LoginBottomViewHeight, view.width, LoginBottomViewHeight)
        _bottomView.backgroundColor = UIColor.white
        _loginView.addSubview(_loginBottomView)
        
        let line:UIView = UIView()
        line.backgroundColor = UIColor(hex: 0xd0d0d0)
        line.frame = CGRectMake(10, 36, _loginBottomView.width - 20, 1)
        _loginBottomView.addSubview(line)
        
        let ssoLabel:UILabel = UILabel()
        ssoLabel.text = "快速登录"
        ssoLabel.textColor = UIColor(hex: 0xa4a4a4)
        ssoLabel.font = UIFont.systemFont(ofSize: 12)
        ssoLabel.textAlignment = .center
        ssoLabel.sizeToFit()
        ssoLabel.width += 15
        ssoLabel.backgroundColor = UIColor.white
        ssoLabel.center = CGPointMake(line.width * 0.5, line.y)
        _loginBottomView.addSubview(ssoLabel)
        
        var buttons:[UIButton] = []
        let weixinLoginBtn:UIButton = UIButton(type:.system)
        weixinLoginBtn.setBackgroundImage(UIImage(named:"auth_icon_weixin"), for: .normal)
        weixinLoginBtn.sizeToFit()
        weixinLoginBtn.frame = CGRectMake(0, 62, weixinLoginBtn.width, weixinLoginBtn.height)
        weixinLoginBtn.addTarget(self, action: #selector(wechatBtnTapped), for: .touchUpInside)
        _loginBottomView.addSubview(weixinLoginBtn)
        buttons.append(weixinLoginBtn)
        
        let QQLoginBtn:UIButton = UIButton(type:.system)
        QQLoginBtn.setBackgroundImage(UIImage(named:"auth_icon_qq"), for: .normal)
        QQLoginBtn.sizeToFit()
        QQLoginBtn.frame = CGRectMake(weixinLoginBtn.right + 20, 62, QQLoginBtn.width, QQLoginBtn.height)
        QQLoginBtn.addTarget(self, action: #selector(loginWithQQ), for: .touchUpInside)
        QQLoginBtn.isHidden = !QQSDKHelper.QQAppInstalled
        _loginBottomView.addSubview(QQLoginBtn)
        if QQSDKHelper.QQAppInstalled
        {
            buttons.append(QQLoginBtn)
        }
        
        let weiboLoginBtn:UIButton = UIButton(type:.system)
        weiboLoginBtn.setBackgroundImage(UIImage(named:"auth_icon_sina"), for: .normal)
        weiboLoginBtn.sizeToFit()
        weiboLoginBtn.frame = CGRectMake(QQLoginBtn.right + 20, 62, weiboLoginBtn.width, weiboLoginBtn.height)
        weiboLoginBtn.addTarget(self, action: #selector(loginWithWeibo), for: .touchUpInside)
        _loginBottomView.addSubview(weiboLoginBtn)
        buttons.append(weiboLoginBtn)
        
        LayoutUtil.distributeHAverageABS(buttons, containerWidth: _loginBottomView.width)
        
    }
    
    //手机登录
    private func loginWithPhone(phone:String, password:String)
    {
        let req = SWLoginReq()
        req.phone = phone
        req.password = password
        //req.requestKey = key
        req.successCallback = {[weak self] response,cache in
            if let response = response as? SWLoginRsp,
                let data = response.data,
                let account = SWMainAccount(response:data)
            {
                account.phone = phone
                self?.loginSuccess(account: account)
            }
            else
            {
                self?.loginFail(SWError.DefaultNetworkError)
            }
        }
        req.failCallback = {[weak self] error in
            self?.loginFail(error)
        }
        load(req)
    }
    
    //获取邀请信息
    private func fetchInvitation()
    {
        let req = SWInvitationFetchReq()
        req.successCallback = {[weak self] response,cache in
            if let invitationsRsp = (response as? SWInvitationFetchRsp)?.invitations
            {
                SVProgressHUD.dismiss()
                let invitations = invitationsRsp.flatMap({SWInvitation(invitation: $0)})
                if let invitation = invitations.valueAt(0)
                {
                    let viewController = SWInvitationHandleViewController(invitation: invitation)
                    viewController.forceSupplement = true
                    self?.navigationController?.pushViewController(viewController, animated: true)
                }
                else
                {
                    let viewController = SWChildAddViewController()
                    viewController.forceSupplement = true
                    self?.navigationController?.pushViewController(viewController, animated: true)
                }
            }
            else
            {
                self?.loginFail(SWError.DataError)
            }
        }
        req.failCallback = {[weak self] error in
            self?.loginFail(error)
        }
        load(req)
    }
    
    private func loginSuccess(account:SWMainAccount)
    {
        SWAccountManager.sharedManager().loginSuccess(account:account)
        
        //登陆完成后，如果还没有家庭，则获取家庭邀请信息
        var childrenCount:Int = account.children?.count ?? 0
        //childrenCount = 0
        if childrenCount > 0
        {
            SVProgressHUD.showSuccess(withStatus:"登陆成功")
            SWMainApplication.sharedApplication.rootViewController?.showMainContent()
        }
        else
        {
            //fetchInvitation()
            SVProgressHUD.dismiss()
            let viewController:SWChildInfoSupplementViewController = SWChildInfoSupplementViewController()
            navigationController?.pushViewController(viewController, animated: true)
        }
    }
    
    private func loginFail(_ error:NSError)
    {
        SVProgressHUD.showError(withStatus:error.message)
        _loginBtn.isEnabled = true
    }
    
    //微博登录成功
    func weiboSignInSuccess(uid:String, userInfo:WeiboSignInUser?)
    {
        if let userInfo = userInfo , uid != ""
        {
            let account:SWConnectionAccount = SWConnectionAccount(user: userInfo)
            SSOLogin(account, platform:.Weibo)
        }
        else
        {
            loginFail(SWError.DefaultNetworkError)
        }
    }
    
    //微博登录失败
    func weiboSignInFail(code:WeiboErrorCode)
    {
        if code == WeiboErrorCode.Auth_Cancel || code == WeiboErrorCode.Auth_Denied
        {
            SVProgressHUD.showError(withStatus:"您已经取消或拒绝登录")
        }
        else
        {
            loginFail(SWError.DefaultNetworkError)
        }
    }
    
    func weixinSignInSuccess(openID:String, userInfo:Wechat.User?)
    {
        if let userInfo = userInfo , openID != ""
        {
            let account:SWConnectionAccount = SWConnectionAccount(user: userInfo)
            SSOLogin(account, platform:.Wechat)
        }
        else
        {
            loginFail(SWError.DefaultNetworkError)
        }
    }
    
    //微信登陆失败
    func weixinSignInFail(code:Wechat.ErrorCode)
    {
        if code == Wechat.ErrorCode.Cancel || code == Wechat.ErrorCode.Denied
        {
            SVProgressHUD.showError(withStatus:"您已经取消或拒绝登录")
        }
        else
        {
            loginFail(SWError.DefaultNetworkError)
        }
    }
    
    //QQ登陆成功
    func QQSignInSuccess(openID:String, userInfo:QQSDK.User?)
    {
        if let userInfo = userInfo , openID != ""
        {
            let account:SWConnectionAccount = SWConnectionAccount(user: userInfo)
            SSOLogin(account, platform:.QQ)
        }
        else
        {
            loginFail(SWError.DefaultNetworkError)
        }
    }
    
    func QQSignInFail(code:QQSDK.ErrorCode)
    {
        if code == QQSDK.ErrorCode.Cancel || code == QQSDK.ErrorCode.Denied
        {
            SVProgressHUD.showError(withStatus:"您已经取消或拒绝登录")
        }
        else
        {
            loginFail(SWError.DefaultNetworkError)
        }
    }
    
    func textFieldShouldReturn(_ textField: UITextField) -> Bool
    {
        loginBtnTapped()
        return false
    }
    
    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool
    {
        var inputEnable:Bool = true
        if textField == _telTextField
        {
            //手机号限制只能输入20个以内的数字
            let MaxCount:Int = 20
            inputEnable = string == "" || ((textField.text?.length ?? 0) + string.length < MaxCount && Regex("^[\\d-]+$").test(string))
        }
        return inputEnable
    }
    
//    func textFieldDidBeginEditing(textField: UITextField)
//    {
//        UIView.animate(withDuration:0.3, animations: {
//            self._loginView.y = 0
//        })
//    }
    
    @objc private func viewTapped()
    {
        view.endEditing(true)
        UIView.animate(withDuration: 0.3, animations: {
            self._loginView.y = self.view.height
        }, completion: {finish in
            self._loginTopView.height = self.LoginTopViewNormalHeight
            self._loginBottomView.y = self._loginTopView.bottom
            self._loginView.height = self._loginBottomView.bottom
        })
    }
    
    @objc private func close()
    {
        self.dismiss(animated:true, completion: {
            
            //WeixinHelper.shared().authViewController = nil
            //WeixinHelper.shared().failCallback = nil
            //WeixinHelper.shared().successCallback = nil
            
        })
        SVProgressHUD.dismiss()
    }
    
    @objc private func loginBtnTapped()
    {
        let userName:String = _telTextField.text ?? ""
        let password:String = _passwordTextField.text ?? ""
        if userName == ""
        {
            SVProgressHUD.showError(withStatus:"输入手机号")
            return
        }
        if password == ""
        {
            SVProgressHUD.showError(withStatus:"输入密码")
            return
        }
        _loginBtn.isEnabled = false
        SVProgressHUD.show(withStatus:"登录中...")
        loginWithPhone(phone: userName, password: password)
    }
    
    @objc private func resetBtnTapped()
    {
        navigationController?.pushViewController(SWPasswordResetViewController(), animated: true)
    }
    
    @objc private func wechatBtnTapped()
    {
        WeixinHelper.shared().auth()
        if WeixinHelper.wechatAppInstalled
        {
            SVProgressHUD.show(withStatus:"登录中...")
        }
    }
    
    @objc private func loginWithQQ()
    {
        SVProgressHUD.show(withStatus:"登录中...")
        QQSDKHelper.shared().auth()
    }
    
    //第三方平台登陆返回
    private func SSOLogin(_ connectionAccount:SWConnectionAccount, platform:ConnectionPlatform)
    {
        let req = SWSSOLoginReq()
        req.connectionAccount = connectionAccount
        req.platform = platform
        req.successCallback = {[weak self] response, cache in
            if let response = response as? SWSSOLoginRsp,let data = response.data
            {
                if let status = SWAccountAuthStatus(rawValue:data.status ?? -1), status == .Success,
                    let account = SWMainAccount(response: data)
                {
                    if platform == .Weibo{
                        account.weiboAccount = connectionAccount
                    }else{
                        account.wechatAccount = connectionAccount
                    }
                    self?.loginSuccess(account: account)
                }
                else
                {
                    SVProgressHUD.dismiss()
                    let viewController:SWRegisterViewController = SWRegisterViewController()
                    viewController.ssoTicket = data.ssoTempticket ?? ""
                    self?.navigationController?.pushViewController(viewController, animated: true)
                }
            }
            else
            {
                self?.loginFail(SWError.DefaultNetworkError)
            }
        }
        req.failCallback = {[weak self] error in
            self?.loginFail(error)
        }
        load(req)
    }
    
    func scrollADImage(_ scrollADImage: ScrollADImage, didScrollToIndex index: Int)
    {
        _pageControl.currentPage = index
    }
    
    func scrollADImage(_ scrollADImage: ScrollADImage, didSelectIndex index: Int)
    {
        print("didSelectIndex")
        viewTapped()
    }
    
    @objc private func loginWithWeibo()
    {
        if WeiboHelper.weiboAppInstalled
        {
            SVProgressHUD.show(withStatus:"登录中...")
        }
        WeiboHelper.shared().auth()
    }
    
    @objc private func closeBtnTapped()
    {
        dismiss(animated:true, completion: nil)
    }
    
    //键盘即将浮出
    @objc private func keyboardWillShow(_ notification:Notification)
    {
        if let userInfo = notification.userInfo,let _ = view.window
        {
            let keyboardFrame:CGRect = userInfo[UIKeyboardFrameEndUserInfoKey] as? CGRect ?? CGRectZero
            let duration:Double = userInfo[UIKeyboardAnimationDurationUserInfoKey] as? Double ?? 0.3
            let Grid:CGFloat = 20
            let dstY:CGFloat = view.height - keyboardFrame.height - LoginTopViewNormalHeight - Grid
            let loginTopViewHeight:CGFloat = view.height - LoginBottomViewHeight - dstY
            let loginViewHeight:CGFloat = view.height - dstY
            UIView.animate(withDuration: duration, animations: {
                self._loginTopView.height = loginTopViewHeight
                self._loginView.frame = CGRectMake(0, dstY, self._loginView.width, loginViewHeight)
            })
        }
    }
    
    @objc private func showLoginViewBtnTapped()
    {
        let y:CGFloat = view.height - _loginView.height
        UIView.animate(withDuration: 0.3, animations: {
            self._loginView.y = y
        })
    }
    
    @objc private func regBtnTapped()
    {
        navigationController?.pushViewController(SWRegisterViewController(), animated: true)
    }
    
}
